;;; -*- mode: lisp; coding: utf-8; -*-

(in-package :cl-tmcl)





(define-condition skip-tmcl-phase
  (simple-condition) 
  ((alternative  
     :initarg :alternative
     :initform nil
     :reader skip-tmcl-phase-alternative)))





(defun call-filters (filters arg)
  (let ((perm arg))
    (dolist (cur-filter filters)
      (setf perm (funcall cur-filter perm)))
    perm))




(defmacro skippable-phase (&rest body)
  `(handler-case 
     (progn ,@body)
     (skip-tmcl-phase (c) 
       (skip-tmcl-phase-alternative c))))
       



(defmacro call-before-after-filters (befores afters arg &rest body)
  (alexandria:with-gensyms (result%)
    `(let ((,result% (skippable-phase 
                      (call-filters ,befores ,arg)
                      (progn ,@body))))
       (call-filters ,afters ,result%))))





(defparameter *before-read-template-file-filters* '())
(defparameter *after-read-template-file-filters* '())


(defparameter *before-render-string-filters* '())
(defparameter *after-render-string-filters* '())


(defparameter *before-transform-string-filters* '())
(defparameter *after-transform-string-filters* '())


(defparameter *before-read-from-string-filters* '())
(defparameter *after-read-from-string-filters* '())


(defparameter *before-eval-lambda-form-filters* '())
(defparameter *after-eval-lambda-form-filters* '())


(defparameter *before-funcall-template-filters* '())
(defparameter *after-funcall-template-filters* '())






;;; EOF